package com.leyou.item.dto;

import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author YYP
 * @date 2020/12/29
 * 规格参数DTO：
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class SpecParamDTO extends BaseDTO {
    private Long id; //规格参数id
    private Long categoryId;  //商品分类id
    private Long groupId;   //规格组id
    private String name;    //规格参数名称
    private Boolean numeric; //是否是数值类型
    private String unit;  //数字单位
    private Boolean generic; //是否是普通参数
    private Boolean searching; //是否参与搜索
    private String segments;  //可选数值范围
    private String options;   //规格参数待选项

    private Object value;

    public SpecParamDTO(BaseEntity entity){
        super(entity);
    }

    public static <T extends BaseEntity> List<SpecParamDTO> convertEntityList(Collection<T> list) {
        if(list == null){
            return Collections.emptyList();
        }
        return list.stream().map(SpecParamDTO::new).collect(Collectors.toList());
    }

}
